package com.techysky.util;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class NetworkInterfaceTest {

	public static void main(String[] args) throws Exception {
		
		
		Process p = Runtime.getRuntime().exec("cmd.exe /c arp -a");
		InputStreamReader isr = new InputStreamReader(p.getInputStream(),"gbk");
		BufferedReader br = new BufferedReader(isr);
		String line = null;
		String pattern = "([\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3}.[\\d]{1,3})";
		List<String>  ips= new  ArrayList<String>();
		// 创建 Pattern 对象
		Pattern r = Pattern.compile(pattern);
		while ((line = br.readLine()) != null) {
			if(line.indexOf("动态")!=-1){
				Matcher m = r.matcher(line);
				if(m.find()){
				
					ips.add(m.group());
				}
			}
		}
		
		if(ips.size()>0){
			   System.out.println(ips.get(0));
		}
		
	}

}